package com.guli.mall.serviceBase.config;

import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.WebFluxCallbackManager;
import com.guli.mall.serviceBase.sentinel.MySentinelBlockRequestHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.servlet.Filter;

/*
 * @Author 罗俊
 * @date 2020/12/6 - 9:39 下午
 *
 */
@Slf4j
@ConditionalOnClass(WebCallbackManager.class)
public class SentinelConfig {

    /**
     * sentinel 1.8 设置了没用
     */
//    @PostConstruct
    public SentinelConfig() {

        log.info("sentinel 1.8 以前：正在配置熔断、限流、降级统一返回消息 sentinel UrlBlockHandler ..");

        /*
        * 需要引入
            <dependency>
                <groupId>com.alibaba.csp</groupId>
                <artifactId>sentinel-web-servlet</artifactId>
            </dependency>

          才可以使用 WebCallbackManager
        * */
        MySentinelBlockRequestHandler mySentinelBlockRequestHandler = new MySentinelBlockRequestHandler();



        WebCallbackManager.setUrlBlockHandler(mySentinelBlockRequestHandler);

    }


}
